package com.itita.ww2.game.user.event;

import java.util.Iterator;
import java.util.Vector;

import com.itita.ww2.game.enums.ContributeType;
import com.itita.ww2.model.user.UserProfile;
import com.itita.ww2.model.worldmap.Base;
import com.itita.ww2.puredb.model.AllianceMember;
import com.itita.ww2.puredb.model.UserAllianceLog;
import com.smartfoxserver.v2.entities.data.ISFSObject;

/**
 * 用户事件分发
 * @author NorthLan
 *
 */
public class UserEventDispatch {
	private static Vector<IUserOccupiedBaseListener> m_UserOccupiedBaseListeners = new Vector<>();
	private static Vector<IUserDefeatedBaseListener> m_UserDefeatedBaseListeners = new Vector<>();
	private static Vector<IUserAllianceContributeChangedListener> m_UserContributeAllianceListeners = new Vector<>();
	private static Vector<IUserBaseDonateListener> m_BaseDonateListeners = new Vector<>();

	public static void addListener(IUserOccupiedBaseListener listener) {
		m_UserOccupiedBaseListeners.add(listener);
	}

	public static void addListener(IUserDefeatedBaseListener listener) {
		m_UserDefeatedBaseListeners.add(listener);
	}

	public static void addListener(IUserAllianceContributeChangedListener listener) {
		m_UserContributeAllianceListeners.add(listener);
	}

	public static void addListener(IUserBaseDonateListener listener) {
		m_BaseDonateListeners.addElement(listener);
	}

	/**
	 * 据点等级捐献触发器
	 * @param flag 是否升级成功
	 */
	public static void onBaseLvDonate(UserProfile userProfile, Base base, ISFSObject resObj, boolean flag) {
		for (Iterator<IUserBaseDonateListener> iter = m_BaseDonateListeners.iterator(); iter.hasNext();) {
			iter.next().onBaseLvDonate(userProfile, base, resObj, flag);
		}
	}

	/**
	 * 据点强化捐献触发器
	 * @param flag 是否强化成功
	 */
	public static void onBaseEnDonate(UserProfile userProfile, Base base, ISFSObject resObj, boolean flag) {
		for (Iterator<IUserBaseDonateListener> iter = m_BaseDonateListeners.iterator(); iter.hasNext();) {
			iter.next().onBaseEnDonate(userProfile, base, resObj, flag);
		}
	}

	/**
	 * 玩家-联盟 贡献度变化
	 */
	public static void onUserAllianceContributeChanged(UserProfile userProfile,
			UserAllianceLog userAlContributionLog, AllianceMember allianceMember, int changedAmount,
			ContributeType type) {
		for (Iterator<IUserAllianceContributeChangedListener> iter = m_UserContributeAllianceListeners.iterator(); iter
				.hasNext();) {
			iter.next().onUserContributeAllianceChanged(userProfile, userAlContributionLog, allianceMember,
					changedAmount, type);
		}
	}

	/**
	 * 玩家占领据点
	 */
	public static void onUserDefeatedBase(UserProfile atkProfile, UserProfile originProfile, Base base) {
		for (Iterator<IUserDefeatedBaseListener> iter = m_UserDefeatedBaseListeners.iterator(); iter.hasNext();) {
			iter.next().onUserDefeatedBase(atkProfile, originProfile, base);
		}
	}

	/**
	 * 玩家占领据点
	 */
	public static void onUserOccupiedBase(UserProfile profile, UserProfile preProfile, String preCityOwnerAid,
			Base base) {
		for (Iterator<IUserOccupiedBaseListener> iter = m_UserOccupiedBaseListeners.iterator(); iter.hasNext();) {
			iter.next().onUserOccupiedBase(profile, preProfile, preCityOwnerAid, base);
		}
	}
}
